<div style="height: 100%;background:rgb(238,238,238);margin:0;padding:0;">
		<div class="titletop">充值<img class="titleimg" src="<?php echo $logo ?>"/></div>
        <div class="panel2" style="margin-top:10px;">
            <div class="lablecustom">手机：</div>
            <input type="number" maxlength="12" id="phone" class="inputcustom" placeholder="请输入手机号码" value='' />
        </div>
        <div class="panel2">
            <div class="lablecustom">卡号：</div>
            <input type="text" maxlength="20" id='cardno' class="inputcustom" placeholder="请输入卡号" value='' />
        </div>
		<div class="panel2" style="height:20px;">
			<div class="lablecustom"></div>
			<input type="checkbox" id='female' />
			<label for="female">记住我的账号信息</label> 
        </div>

        <div style="margin-top:10px;width:100%;border:0.5px solid #dbdbdb;">
            <div class="lablecustom" style="margin-top:30px;">选择金额：</div>
            <div style="width:55%;margin-left:0px;float:left;">
                <div class="money" onclick="setmoeny(50)">50元</div>
                <div class="money" onclick="setmoeny(100)">100元</div>
                <div class="money" onclick="setmoeny(200)">200元</div>
                <div class="money" onclick="setmoeny(500)">500元</div>
            </div>
        </div>
        <div class="panel2" style="margin-top:100px;">
            <div class="lablecustom"></div>
            <input type="number" maxlength="5" id="paymoney" class="inputcustom" placeholder="输入您想充值的金额" value='' />
        </div>
		 <div class="panel2"  style="margin-top:0px;">
            <div class="lablecustom">充值次数：</div>
            <input type="number" maxlength="2" id="paynum" class="inputcustom" placeholder="输入您想充值的次数" value='1' />
        </div>
        <div align="center" style="margin-top:10px;">
            <button style="width: 90%; height: 50px; border-radius: 5px; background-color: rgb(217,144,52);
                border: 0px #FE6714 solid; cursor: pointer; color: white; font-size: 16px;" type="button"
                    onclick="jsApiCall()">
                充值
            </button>
        </div>
		<div class="footer" id="footer">
			<img src="/weixin/images/logo.png" style="height: 20px;">本服务由上海鹏企自动化科技有限公司提供
		</div>
    </div>
    

    <div id="pay" class="payalert">
        <div class="msgpanl">
            <div class="tiptitle">
                支付确认
            </div>
            <div class="txtTip">
                手机号码：<span style="color:black;" id="myphone">13162371127</span>
            </div>
            <div class="txtTip">
                充值卡号：<span style="color:black;" id="myphone">wen87987</span>
            </div>
            <div class="txtTip">
                充值金额：<span style="color:#d81e06;" id="mymoney">30元</span>
            </div>
            <div class="paydiv">
                <div class="payconfirm">
                    <a href="#" id="confirmPay" style="text-decoration:none;">确认支付</a>
                </div>
                <div class="paycancel" onclick="closepay()">
                    取消
                </div>
            </div>
        </div>
    </div>
	<script type="text/javascript" src="../js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript">
	var bodyHeight=document.body.clientHeight;
	var x=document.getElementById("footer");
	var rect=x.getBoundingClientRect();
	var marginTop=bodyHeight-rect.top-rect.height-20;
	marginTop=marginTop>0?marginTop:0;
	$("#footer").css("margin-top",marginTop);

	function setmoeny(money){
		$("#paymoney").val(money);
	}

	 function isNumber(val){
		var regPos = /^\d+(\.\d+)?$/; //非负浮点数
		var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
		if(regPos.test(val) || regNeg.test(val)){
			return true;
		}else{
			return false;
		}
	}
	//调用微信JS api 支付
	function jsApiCall()
	{
		var phone=$("#phone").val();
		if(phone.length==0)
		{
			alert('请填写手机号码');
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/;
		var flag = reg.test(phone);
		if(!flag)
		{
			alert('请填写有效的手机号码');
			return;
		}
		var moeny=$("#paymoney").val();
		if(moeny.length==0)
		{
			alert('请填写或者选择支付金额');
			return;
		}
		if(!isNumber(moeny))
		{
			alert('充值金额只能输入数字');
			return;
		}
		var paynum=$("#paynum").val();
		if(paynum.length>0&&!isNumber(paynum))
		{
			alert('充值次数只能输入数字');
			return;
		}

		if($("#female")[0].checked==true)
		{
			setAllCookie();
		}
		else
		{
			setCookie('phone', "", 365)
			setCookie('cardno', "", 365)
		}
		$.ajax({
			url:'pays/index.php/WebPay/getPayParam',
			type:'POST',
			data:{
				money:moeny,
				phone:phone,
				cardno:$('#cardno').val(),
				num:paynum
			},
			dataType:'json',
			success:function(data){
					console.log(data);
				if(data.code==-1){
					alert(data.message);
				}
				else{
					postpay(data);
				}
				//alert(JSON.stringify(data))
			},
			error:function(data){
				console.log(data);
				alert('JS请求支付参数错误，请联系管理员');
			}
		});
		return;
	}



	function postpay(data){
		switch(data.type){
			case 'wechat':
				WeixinJSBridge.invoke(
					'getBrandWCPayRequest',
					data.result,function(res){
					//WeixinJSBridge.log(res.err_msg);
					//alert(res.err_code+res.err_desc+res.err_msg);
					//通知卡充值
					});
				break;
			case 'wechatscan':
				alert(data.result);
				break;
			case 'union':
				window.location.href=data.result;
				break;
			default:
				break;
		}
	}


	function callpay()
	{
		if (typeof WeixinJSBridge == "undefined"){
		    if( document.addEventListener ){
		        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
		    }else if (document.attachEvent){
		        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
		        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
		    }
		}else{
		    jsApiCall();
		}
	}
	
	function GetQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return "";
	}

	function getCookie(c_name) {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=")
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1
                c_end = document.cookie.indexOf(";", c_start)
                if (c_end == -1) c_end = document.cookie.length
                return unescape(document.cookie.substring(c_start, c_end))
            }
        }
        return ""
    }

    function setCookie(c_name, value, expiredays) {
        var exdate = new Date()
        exdate.setDate(exdate.getDate() + expiredays)
        document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + exdate.toGMTString())
    }

    function checkCookie() {
        var phone = getCookie('phone');
        if (phone != null && phone != "")
        { $("#phone").val(phone) ;$("#female").attr("checked",true);}
        else {
            phone = $("#phone").val();
            if (phone != null && phone != "") {
                setCookie('phone', phone, 365)
            }
        }

        var cardno = getCookie('cardno');
        if (cardno != null && cardno != "")
        { $("#cardno").val(cardno) }
        else {
            cardno = $("#cardno").val();
            if (cardno != null && cardno != "") {
                setCookie('cardno', cardno, 365)
            }
        }
    }

	function setAllCookie(){
		phone = $("#phone").val();
        if (phone != null && phone != "") {
            setCookie('phone', phone, 365)
        }
		cardno = $("#cardno").val();
        if (cardno != null && cardno != "") {
            setCookie('cardno', cardno, 365)
        }
	}
	checkCookie();
	</script>
